package utils;

import java.util.Scanner;

/**
 * @program: JavaExam
 * @description:处理输入异常
 * @create: 2021-12-08 20:50
 * @Date 2021/12/8
 **/

public class NumUtils {
    public static final double oneHundred = 100;
    public static final double fiveHundred = 100;
    public static final double oneThousand = 100;

    public static int intPutNum(String mgs) {
        int arr[] = {48, 49, 50, 51, 52, 53, 54, 55, 56, 57};

        int account = 0;
        char[] chars = mgs.toCharArray();
        //判断输入的字符串有几个数字
        for (int i = 0; i < chars.length; i++) {
            for (int j = 0; j < arr.length; j++) {
                if ((int) chars[i] == arr[j]) {
                    ++account;//记录字符串的个数
                }
            }
        }
        if(chars.length==account){
            return Integer.parseInt(mgs);
        }else{
            return -1;
        }
    }
    public static double getMoney(int times){
        if(times==1){
            return 100.0;
        }else if(times ==2){
            return 500.0;
        }else if(times ==3){
            return 1000.0;
        }
        return 0.0;
    }
    public static Integer backChoiceInfo(Scanner scanner,Integer start ,Integer end){
        ViewUtils.inputYourChoice();
        String input = scanner.next();
        int choice = intPutNum(input);
        if(choice >= start && choice <= end ){
            return choice;
        }else{
            System.out.println("输入非法，输入的范围为"+"["+start + ","+end + "]");
            return backChoiceInfo (scanner,start,end);
        }
    }
    public static Double backDoubleInfo(Scanner scanner){
        ViewUtils.inputYourChoice();
        return scanner.nextDouble();
    }
}
